package com.usooft.metaTalent.core.system.service.basic;

import com.usooft.metaTalent.core.system.entity.Dict;
import com.usooft.metaTalent.core.system.query.DictQuery;
import com.usooft.metaTalent.core.system.service.DictService;
import com.usooft.metaTalent.core.system.service.base.BaseDictService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

import static com.usooft.framework.core.utils.Checks.checkNotNull;

@Service
@RequiredArgsConstructor
public class BasicDictService extends BaseDictService implements DictService {

    @Override
    @Transactional
    public Dict create(String name, String description) {
        return internalAdd(name, description);
    }

    @Override
    @Transactional
    public void edit(Dict dict, String name, String description) {
        dict.setName(name);
        dict.setDescription(description);
        internalUpdate(dict);
    }

    @Override
    @Transactional
    public Optional<? extends Dict> findByName(String name) {
        checkNotNull(name, "必须提供名称");
        return findOne(DictQuery.Filter.builder()
                .nameIs(name)
                .build());
    }

    // region 自动生成
    // endregion
}